package com.logistics.map.controller;

import com.logistics.map.entity.model.MapPager;
import com.logistics.map.entity.model.MapSave;
import com.logistics.map.service.MapService;
import com.logistics.utils.aspect.annotation.LoggerListener;
import com.logistics.utils.constants.LoggerMethod;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("lgs/map")
public class MapController {

    @Autowired
    private MapService mapService;

    /**
     * 查询地图列表
     * @param param
     * @return
     */
    @PostMapping("pager")
    @LoggerListener(businessName = "查询地图列表", methodName = LoggerMethod.SEARCH)
    public ResponseEntity pager(@RequestBody MapPager param){
        return ResponseUtil.success(mapService.pager(param));
    }

    /**
     * 查询地图详细
     * @param id
     * @return
     * @throws MessageException
     */
    @GetMapping("details/{id}")
    @LoggerListener(businessName = "查询地图详细", methodName = LoggerMethod.SEARCH)
    public ResponseEntity details(@PathVariable("id") String id) throws MessageException {
        return ResponseUtil.success(mapService.details(id));
    }

    /**
     * 删除
     * @param ids
     * @return
     * @throws MessageException
     */
    @DeleteMapping("remove/{ids}")
    public ResponseEntity remove(@PathVariable("ids") String ids) throws MessageException {
        mapService.delete(ids);
        return ResponseUtil.success();
    }

    /**
     * 保存地图信息
     * @param save
     * @return
     * @throws MessageException
     */
    @PutMapping("save")
    public ResponseEntity save(@RequestBody MapSave save) throws MessageException {
        return ResponseUtil.success(mapService.save(save));
    }
}
